﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebStickyNotes.Contracts;
using WebStickyNotes.Helpers;

namespace WebStickyNotes.Test
{
    [TestClass]
    public class EncyptionHelperTest
    {

        [TestMethod]
        public void HashString_SimpleSting_HashedValue()
        {
            const string password = "test";
            var encrypted = EncryptionHelper.HashString(password);

            Assert.AreNotEqual(password, encrypted);
        }

        [TestMethod]
        public void ComparePassword_Same_ExpectTrue()
        {
            const string password = "test";
            var encrypted = EncryptionHelper.HashString(password);

            var taskPerson = new TaskPerson { Password = encrypted };

            var result = EncryptionHelper.ComparePassword(taskPerson, password);

            Assert.IsTrue(result);
        }

        [TestMethod]
        public void ComparePassword_Different_ExpectFalse()
        {
            const string password = "test";
            // Change the password very slightly to test it doesn't match
            const string differentPassword = "Test";
            var encrypted = EncryptionHelper.HashString(password);

            var taskPerson = new TaskPerson { Password = encrypted };

            var result = EncryptionHelper.ComparePassword(taskPerson, differentPassword);

            Assert.IsFalse(result);
        }

        [TestMethod]
        public void HashString_AlreadyHashed_SameValue()
        {
            const string password = "##D9WQko234-8KJFS(jdklOWKD";
            var encrypted = EncryptionHelper.HashString(password);

            Assert.AreEqual(password, encrypted);
        }
    }
}
